package com.xplusplus.security.repository;

import com.xplusplus.security.domain.TemporaryProjectHeader;
import com.xplusplus.security.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Collection;
import java.util.Date;

/**
 * @Author: zhouweixin
 * @Description:
 * @Date: Created in 11:10 2018/9/4
 * @Modified By:
 */
public interface TemporaryProjectHeaderRepository extends JpaRepository<TemporaryProjectHeader, Long> {
    /**
     * 通过日期查询
     *
     * @param date1
     * @param date2
     * @return
     */
    Page<TemporaryProjectHeader> findByDateBetween(Date date1, Date date2, Pageable pageable);

    /**
     * 通过状态查询
     *
     * @param status
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByStatus(Integer status, Pageable pageable);

    /**
     * 通过申请人查询-分页
     *
     * @param user
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByApplicant(User user, Pageable pageable);

    /**
     * 通过申请人和申请日期查询-分页
     *
     * @param user
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByApplicantAndApplyTimeBetween(User user, Date date1, Date date2, Pageable pageable);

    /**
     * 通过经办人查询-分页
     *
     * @param user
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByOperator(User user, Pageable pageable);

    /**
     * 通过经办人和申请日期查询-分页
     *
     * @param user
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByOperatorAndApplyTimeBetween(User user, Date date1, Date date2, Pageable pageable);

    /**
     * 通过审核人查询-分页
     *
     * @param user
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByAuditor(User user, Pageable pageable);

    /**
     * 通过审核人和申请日期查询-分页
     *
     * @param user
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByAuditorAndApplyTimeBetween(User user, Date date1, Date date2, Pageable pageable);

    /**
     * 更新审核状态
     *
     * @param status
     * @param auditTime
     * @param note
     * @param id
     */
    @Modifying
    @Query(value = "update TemporaryProjectHeader t set t.status=?1, t.auditTime=?2, t.note=?3 where t.id=?4")
    void updateStatus(int status, Date auditTime, String note, long id);

    /**
     * 通过主键和申请人主键查询
     *
     * @param ids
     * @param applicantId
     */
    void deleteByIdInAndApplicant(Collection<Long> ids, User applicantId);

    /**
     * 通过状态和申请时间查询-分页
     *
     * @param status
     * @param startDate
     * @param endDate
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByStatusAndApplyTimeBetween(Integer status, Date startDate, Date endDate, Pageable pageable);

    /**
     * 通过申请人和状态查询-分页
     *
     * @param applicant
     * @param status
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByApplicantAndStatus(User applicant, Integer status, Pageable pageable);

    /**
     * 通过申请人，状态和申请时间查询-分页
     *
     * @param applicant
     * @param status
     * @param startDate
     * @param endDate
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByApplicantAndStatusAndApplyTimeBetween(User applicant, Integer status, Date startDate, Date endDate, Pageable pageable);

    /**
     * 通过经办人和状态查询-分页
     *
     * @param operator
     * @param status
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByOperatorAndStatus(User operator, Integer status, Pageable pageable);

    /**
     * 通过经办人，状态和日期查询-分页
     *
     * @param operator
     * @param status
     * @param startDate
     * @param endDate
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByOperatorAndStatusAndApplyTimeBetween(User operator, Integer status, Date startDate, Date endDate, Pageable pageable);

    /**
     * 通过审核人和状态查询-分页
     *
     * @param auditor
     * @param status
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByAuditorAndStatus(User auditor, Integer status, Pageable pageable);

    /**
     * 通过审核人，状态和申请时间查询-分页
     *
     * @param auditor
     * @param status
     * @param startDate
     * @param endDate
     * @param pageable
     * @return
     */
    Page<TemporaryProjectHeader> findByAuditorAndStatusAndApplyTimeBetween(User auditor, Integer status, Date startDate, Date endDate, Pageable pageable);
}
